package com.woniuxy.driverschool.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.driverschool.entity.Coach;
import com.woniuxy.driverschool.entity.ResponseResult;
import com.woniuxy.driverschool.service.CoachService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/coach")
public class CoachController {
    @Resource
    private CoachService coachService;

    @RequestMapping("/all")
    public ResponseResult<List<Coach>> all(){
        ResponseResult<List<Coach>> responseResult =  new ResponseResult<>();
        responseResult.setState(200);
        responseResult.setMessage("查询所有教练信息");
        responseResult.setData(coachService.showAllCoach());
        return responseResult;
    }

    @RequestMapping("/add")
    public void add(){
        Coach coach = new Coach();
        coachService.addCoach(coach);
    }
    @RequestMapping("/op")
    public ResponseResult<List<Coach>> op(@RequestBody Coach coach){
       ResponseResult<List<Coach>> responseResult =  new ResponseResult<>();
       responseResult.setData(coachService.findCoachByOptions(coach));
       responseResult.setMessage("按条件查询返回教练信息");
       responseResult.setState(200);
       return responseResult;
    }
    @RequestMapping("/page")
    public void fenpage(){
        Page<Coach> page = PageHelper.startPage(2,2);
       List<Coach> list = coachService.showAllCoach();
        PageInfo<Coach> pageInfo = new PageInfo<Coach>(list,2);
        for (Coach coach : pageInfo.getList()){
            System.out.println(coach);
        }

     }

}
